package com.fwyx.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * <p>
 * </p>
 *
 * @author zhuolin
 * @since 2020/3/24
 */
@RestController
@RequestMapping("/api")
public class TestController {


    @Resource
    private RestTemplate restTemplate;

    public String getDefault(String name) {
        return "熔断" + name;
    }

    @GetMapping("/sayHello")
    @HystrixCommand(fallbackMethod = "getDefault")
    public String sayHello(String name) {
        ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://PRODUCER-4/api/sayHello?name=" + name, String.class);

        return responseEntity.getBody();
    }


}
